package com.xywang.interceptor;

import com.xywang.pojo.User;
import com.xywang.util.Constants;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AuthorityManagement implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception {
        User user = (User) req.getSession().getAttribute(Constants.USER_SESSION);
        String method = req.getParameter("method");
        if(method==null){
            method="";
        }
        if (!(method.equals("add") || method.equals("deluser") || method.equals("modifyexe"))) {
            return true;
        }else if(user.getUserRole()==1){
            return true;
        }else{
            System.out.println("有非管理员用户：【"+user.getUserName()+"】试图添加、修改或删除用户！");
            resp.sendRedirect(req.getContextPath()+"/error.jsp");
            return false;
        }
    }

}
